<?php
$this->pageTitle = 'Detail obratu';
?>
<div class="viewForm">
	<h3>Detail obratu
	<?php if (isset($userPermissions['transfer']['edit'])) {
		echo $this->Html->link(__('Uprav', true), array('controller' => 'transfer', 'action' => 'edit', $transfer['Transfer']['id']), array('class' => 'edit'));
	}?>
	</h3>
	<dl>
		<dt>Ponuka:</dt>
		<dd>
			<?php
				if ($transfer['Transfer']['fk_offer_id']) {
					$offerParts = array();
					$offerParts[] = 'Popis: ' . html_entity_decode($this->Html->link($transfer['Offer']['html_description'], array('controller' => 'market', 'action' => 'view', $transfer['Transfer']['fk_offer_id'])));
					if ($transfer['Offer']['fk_client_id']) {
						$offerParts[] = 'Klient: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_client_id']));
					}
					if ($transfer['Offer']['fk_tipster_id']) {
						$offerParts[] = 'Tiper: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_tipster_id']));
					}
					if ($transfer['Offer']['fk_broker_id']) {
						$offerParts[] = 'Maklér: ' . $this->Html->link(htmlspecialchars($transfer['Offer']['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Offer']['fk_broker_id']));
					}
					echo implode('<br />', $offerParts);
				}
			?>
		</dd>

		<?php
			if ($transfer['Transfer']['fk_demand_id']) {
				echo '<dt>Dopyt:</dt><dd>';

				$demandParts = array();
				$demandParts[] = 'Popis: ' . html_entity_decode($this->Html->link($transfer['Demand']['html_description'], array('controller' => 'market', 'action' => 'view', $transfer['Transfer']['fk_demand_id'])));
				if ($transfer['Demand']['fk_client_id']) {
					$demandParts[] = 'Klient: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_client_id']));
				}
				if ($transfer['Demand']['fk_tipster_id']) {
					$demandParts[] = 'Tiper: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_tipster_id']));
				}
				if ($transfer['Demand']['fk_broker_id']) {
					$demandParts[] = 'Maklér: ' . $this->Html->link(htmlspecialchars($transfer['Demand']['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $transfer['Demand']['fk_broker_id']));
				}
				echo implode('<br />', $demandParts);
				}	
				echo '</dd>';
		?>
		
		<dt>Provízia:</dt>
		<dd>
			<?php echo number_format($transfer['Transfer']['commission'], 2, ',', ' ') . ' &euro;'; ?>
		</dd>
		<dt>Referenčný obchod:</dt>
		<dd>
			<?php echo $transfer['Transfer']['referenced'] == 1 ? 'áno' : 'nie'; ?>
		</dd>

	</dl>
	<div class="clear"></div>
	<?php
		if (isset($commissions[1]) && is_array($commissions[1])) {
			echo '<br />';
			echo '<h4>Provízia pre makléra</h4>';
			foreach ($commissions[1] as $broker) {
				echo '<p>' . $broker['type'] . ' - ' . $broker['name'] . ' - ';
				echo $broker['percentage'] . ' % - ' . number_format($broker['value'], 2, ',', ' ') . ' &euro;</p>';
			}
		}

		if (isset($commissions[2]) && is_array($commissions[2]))  {
			echo '<br />';
			echo '<h4>Provízia za ponuku:</h4>';
			foreach ($commissions[2] as $offerCommissioner) {
				echo '<p>' . $offerCommissioner['type'] . ' - ' . $offerCommissioner['name'] . ' - ';
				echo $offerCommissioner['percentage'] . ' % - ' . number_format($offerCommissioner['value'], 2, ',', ' ') . ' &euro;</p>';
			}
		}

		if (isset($commissions[3]) && is_array($commissions[3]))  {
			echo '<br />';
			echo '<h4>Provízia za dopyt:</h4>';
			foreach ($commissions[3] as $demandCommissioner) {
				echo '<p>' . $demandCommissioner['type'] . ' - ' . $demandCommissioner['name'] . ' - ';
				echo $demandCommissioner['percentage'] . ' % - ' . number_format($demandCommissioner['value'], 2, ',', ' ') . ' &euro;</p>';
			}
		}

		if (isset($commissions[4]) && is_array($commissions[4]))  {
			echo '<br />';
			echo '<h4>Provízia pre firmu:</h4>';
			foreach ($commissions[4] as $company) {
				echo '<p>' . $company['type'] . ' - ' . $company['name'] . ' - ';
				echo $company['percentage'] . ' % - ' . number_format($company['value'], 2, ',', ' ') . ' &euro;</p>';
			}
		}

		if (isset($totalCommissioners) && $totalCommissioners) {
			echo '<br /><br />';
			echo '<h4>Provízia celkom:</h4>';
			foreach ($totalCommissioners as $commissioner) {
				echo '<p>' . $commissioner['type'] . ' - ' . $commissioner['name'] . ' - ' .
					$commissioner['total_commission_percentage'] . ' % - ' . number_format($commissioner['total_commission_value'], 2, ',', ' ') . ' &euro;</p>';
			}
		}
	?>
	<div class="clear"></div>
</div>